package com.ali.ttt.webSocket.utils;

import com.ali.ttt.webSocket.cluster.NettyRedisMessageListener;
import com.alibaba.fastjson.JSONObject;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;

/**
 * @Author : yuxl
 * @create 2024/7/15 1:40 PM
 */
@Component
public class MessageUtil {

    @Resource
    private NettyRedisMessageListener nettyRedisMessageListener;

    public void send(ChannelHandlerContext ctx, String msg){
        Channel channel = ctx.channel();
        channel.writeAndFlush(new TextWebSocketFrame(msg));
    }

    public void sendAll(String msg){
        nettyRedisMessageListener.pushMessage(msg);
    }
}
